﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App1AppHandler;
using System.IO;
using System.Xml;

namespace Reborn_WorldServer.App1AppHandler
{
    public class BagPage
    {
        public int PageNumber = -1;
        public Loot[] bagItems = new Loot[28];

        public string toXML(Character sendingToCharacter)
        {
            string result = "";

            StringWriter stringWriter = new StringWriter();
            XmlTextWriter xmldoc = new XmlTextWriter(stringWriter);

            xmldoc.WriteStartElement("bagpage");
            xmldoc.WriteAttributeString("pagenumber", PageNumber.ToString());

            string innerXml = "";
            for (int ctr = 0; ctr < 28; ctr++)
            {
                if (bagItems[ctr] != null)
                    innerXml = innerXml + bagItems[ctr].toXML(sendingToCharacter);
                else
                    innerXml = innerXml + "<i />";
            }
            xmldoc.WriteRaw(innerXml);

            xmldoc.WriteEndElement();
            xmldoc.Flush();

            xmldoc.Close();

            stringWriter.Flush();

            result = stringWriter.ToString();

            return result;
        }
    }

}
